//
//  EPMNewFeatureViewController.m
//  myXianfeng
//
//  Created by 马继鵬 on 17/4/26.
//  Copyright © 2017年 EPM. All rights reserved.
//

#import "EPMNewFeatureViewController.h"
#import "EPMNewFeatureCollectionViewCell.h"
#import "EPMMainTabBarController.h"

@interface EPMNewFeatureViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (weak,nonatomic) UICollectionView* collectionView;
@property (weak,nonatomic)  UIPageControl* pageControl;

@end

@implementation EPMNewFeatureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
    [self addPageControl];
}


- (void)setupUI{
    UICollectionViewFlowLayout* flowLayout = [UICollectionViewFlowLayout new];
    //设置布局属性
    flowLayout.itemSize = [UIScreen mainScreen].bounds.size;
    flowLayout.minimumLineSpacing = 0;
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    UICollectionView* collectionView = [[UICollectionView alloc]initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:flowLayout];
    self.collectionView = collectionView;
    [self.view addSubview:self.collectionView];
    
    collectionView.dataSource = self;
    collectionView.delegate = self;
    collectionView.pagingEnabled = YES;
    collectionView.bounces = NO;
    collectionView.showsVerticalScrollIndicator = NO;
    collectionView.showsHorizontalScrollIndicator = NO;
    
    
    [collectionView registerClass:[EPMNewFeatureCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    
}

- (void)addPageControl{
    UIPageControl* pageControl = [[UIPageControl alloc]init];
    _pageControl = pageControl;
    [self.view insertSubview:pageControl aboveSubview:self.collectionView];
    
    [pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-30);
    }];
    
    pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    pageControl.pageIndicatorTintColor = [UIColor colorWithRed:252/255.0 green:207/255.0 blue:47/255.0 alpha:1.0];
    pageControl.numberOfPages = 4;
    pageControl.currentPage = 0;
}

#pragma mark - 数据源方法实现 -

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 4 ;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    EPMNewFeatureCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.indexPath = indexPath;
    
    [cell setBtnClickBlock:^{
        EPMMainTabBarController* VC = [EPMMainTabBarController new];
        [UIApplication sharedApplication].keyWindow.rootViewController = VC;
        
        //可以设置自定义动画
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
    
    
    return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSInteger item =  scrollView.contentOffset.x / [UIScreen mainScreen].bounds.size.width;
    self.pageControl.currentPage = item;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
